<?php
// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// | Author 似水星辰 [ 2630481389@qq.com ]
// +----------------------------------------------------------------------
// | 中犇软件 技术六部 出品
// +----------------------------------------------------------------------

namespace app\order\validate;

use think\Validate;

/**
 * 退换货填地址验证器
 * @package app\goods\validate
 * @author 似水星辰 [2630481389@qq.com]
 */
class RefundAddress extends Validate
{
    //定义规则
    protected $rule = [
       'receiver_name|收件人' =>[ 'require',"max"=>50,"checkName"],
       'receiver_mobile|手机号' =>[ 'require',"mobile"],
       'receiver_province|省份' =>[ 'require',"max"=>10,"checkTitle"],
       'receiver_city|城市' =>[ 'require',"max"=>10,"checkTitle"],
       'receiver_district|地区' =>[ 'require',"max"=>10,"checkTitle"],
       'receiver_address|收件地址' =>[ 'require',"max"=>150,"checkContent"],
       'receiver_remark|备注' =>[ "max"=>200,"checkContent"],
    ];

    protected $message = [
        "receiver_name.regex"=>"收件人只可以填写中英文、数字、空格和逗号",
        "receiver_province.regex"=>"省份只可以填写中英文、数字、空格和逗号",
        "receiver_city.regex"=>"城市只可以填写中英文、数字、空格和逗号",
        "receiver_city.regex"=>"城市只可以填写中英文、数字、空格和逗号",
        "receiver_address.regex"=>"收件地址只可以填写中英文、数字、空格和逗号",
        "receiver_remark.regex"=>"备注只可以填写中英文、数字、空格和逗号"
    ];

    // 定义验证场景
    protected $scene = [
      
    ];   
    
      
    protected function checkName($value,$rule,$data=[],$filed = ""){
       $check = preg_match('/^[\x{4e00}-\x{9fa5}\x{9fa6}-\x{9fef}\x{3400}-\x{4db5}\x{20000}-\x{2ebe0}a-zA-Z0-9\·\s]+$/u',$value);
        if(!$check){
            return ":attribute只可以填写中英文、数字、空格、圆点";
        }
        return true;
    }
    protected function checkTitle($value,$rule,$data=[],$filed = ""){
        $check = preg_match('/^[\x{4e00}-\x{9fa5}\x{9fa6}-\x{9fef}\x{3400}-\x{4db5}\x{20000}-\x{2ebe0}a-zA-Z0-9\_\—\-\s]+$/u',$value);
        if(!$check){
            return ":attribute只可以填写中英文、数字、空格";
        }
        return true;
    }
    
    protected function checkContent($value,$rule,$data=[],$filed = ""){
        $check = preg_match('/^[\x{4e00}-\x{9fa5}\x{9fa6}-\x{9fef}\x{3400}-\x{4db5}\x{20000}-\x{2ebe0}a-zA-Z0-9\_\—\-\s\,\，]+$/u',$value);
        if(!$check){
            return ":attribute只可以填写中英文、数字、空格和逗号";
        }
        return true;
    }
  
}
